package cn.itcast.itcaststore.web.servlet.client;

import cn.itcast.itcaststore.domain.Notice;
import cn.itcast.itcaststore.serive.NoticeService;
import cn.itcast.itcaststore.serive.ProductService;
import cn.itcast.itcaststore.serive.impl.NoticeServiceImpl;
import cn.itcast.itcaststore.serive.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Auther: 万秋泊
 * @Date: 2021/10/27 10:31
 * @Description:
 */

/**
 * 前台页面展示的Servlet
 * 1.展示最新添加或修改的一条公告
 * 2.展示本周热卖商品
 */
@WebServlet("/ShowIndexServlet")
public class ShowIndexServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.查询最近一条公告，放入request域中，传递到index.jsp页面展示
        NoticeService nService = new NoticeServiceImpl();
        Notice notice = nService.getRecentNotice();
        req.setAttribute("n",notice);
        //2.查询本周热卖的商品，放入request域中，传递到index.jsp页面进行展示
        ProductService pService = new ProductServiceImpl();
        List<Object[]> pList=pService.getWeekHotProduct();
        req.setAttribute("pList",pList);
        //3.请求转发
        req.getRequestDispatcher("/client/index.jsp").forward(req,resp);
    }


}
